/*
 * Copyright (c) 2010-2011 GOV.
 * [Id:MainPageBean.java  11-9-9 PM3:59 poplar.mumu ]
 */
package org.mumu.pawn.beans.common;

import com.google.common.base.Strings;
import org.mumu.pawn.util.FacesUtil;
import org.mumu.pawn.util.StringUtil;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;

/**
 * 页面信息的一些信息
 * <br/>
 *
 * @author poplar.yfyang
 * @version 1.0 11-9-9 PM3:59
 * @since JDK 1.5
 */
@Named("main")
@SessionScoped
public class MainPageBean implements Serializable {
    private static final long serialVersionUID = -1036682464920057258L;

    /**
     * 获取标题
     *
     * @return 标题
     */
    public String getTitle() {
        String view = FacesUtil.getViewParameter(PAGE_VIEW);
        return Strings.isNullOrEmpty(view) ? "首页" :
                actionOperatorBean.getOperate(view).getOperateName();
    }

    /**
     * 获取当前菜单的标志
     * @return 当前菜单的标记
     */
    public String getActiveMenu() {
        String view = FacesUtil.getViewParameter(PAGE_VIEW);
        return Strings.isNullOrEmpty(view) ? "" : view;
    }

    /**
     * 获取实际路径，通过xhtml方式来获取
     *
     * @return 实际路径
     */
    public String getPagePath() {
        String view = FacesUtil.getViewParameter(PAGE_VIEW);
        return Strings.isNullOrEmpty(view) ? "/welcome.xhtml" :
                actionOperatorBean.getOperate(view).getOperateAction();
    }

    /**
     * URL请求参数
     */
    private static final String PAGE_VIEW = "page";

    @Inject
    private ActionOperatorBean actionOperatorBean;
}
